﻿using System;
using System.Text;
using System.Windows.Data;
using System.Windows.Markup;

namespace DynamicMVVM.Demo.UI.Utilities
{
    [MarkupExtensionReturnType(typeof(string))]
    public class LanguageTranslateExtension : MarkupExtension
    {
        private string _key;

        public LanguageTranslateExtension()
        {
            
        }
        public LanguageTranslateExtension(string key)
        {
            _key = key;
        }

        [ConstructorArgument("key")]
        public string Key
        {
            get { return _key; }
            set { _key = value; }
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var binding = new Binding("Value")
                  {
                      Source = new TranslationData(_key)
                  };
            return binding.ProvideValue(serviceProvider);
        }
    }
}
